<?php
abstract class Dmf_Form_Validator
{
    /**
     * The element
     * 
     * @var Dmf_Form_Element 
     */
    private $_element;
    
    /**
     * The default error message
     * 
     * @var string
     */
    protected $_message = 'Unknown error';
    
    /**
     * The form element
     * 
     * @var Dmf_Form 
     */
    public $form;
    
    /**
     * The value of the rule
     * 
     * @var string 
     */
    protected $_value;
    
    /**
     * Constructor
     * 
     * @param Dmf_Form $form
     * @param Dmf_Form_Element $element
     * @param mixed $value 
     */
    public function __construct( Dmf_Form $form, $element, $value = null )
    {
        $this->_element = $element;
        $this->_value = $value;
        $this->form = $form;
    }
    
    /**
     * Get validation type
     * 
     * @return string 
     */
    public function getType()
    {
        $array = explode( '_', get_class( $this ) );
        
        return strtolower( end( $array ) );
    }
    
    /**
     * Get error message
     * 
     * @return string 
     */
    public function getMessage()
    {
        return $this->_message;
    }
    
    /**
     * Get the element
     * 
     * @return Dmf_Form_Element 
     */
    public function element()
    {
        return $this->_element;
    }
    
    /**
     * Check if the rule is valid and validation is ok!
     * 
     * @param string $value 
     */
    abstract function isValid( $value );
}